package com.allinpay.merchantweb.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.allinpay.merchantweb.common.utils.SequenceUtil;
import com.allinpay.merchantweb.constants.ReturnCodeConstants;
import com.allinpay.merchantweb.model.CommPrivilegeInfo;
import com.allinpay.merchantweb.model.PageForLayui;
import com.allinpay.merchantweb.request.CommonReqBean;
import com.allinpay.merchantweb.response.AppCommonResponse;
import com.allinpay.merchantweb.response.ResponseData;
import com.allinpay.merchantweb.service.ITradeQueryService;
import com.google.gson.reflect.TypeToken;

@Service
public class TradeQueryServiceImpl implements ITradeQueryService {

	@Autowired
	RestRequestService restRequestService;
	
	@Override
	public Object compQueryFinanceDetails(Map map) throws Exception {
		// TODO Auto-generated method stub
		CommonReqBean reqBean = new CommonReqBean(); 
		reqBean.setBizContent(map);
		reqBean.setReqSsn(SequenceUtil.getAppReqSsn());
		
		
		AppCommonResponse<ResponseData> respBean = restRequestService.postToAppForSingleByObj
				("/trade/query/compQueryFinanceDetails"
						, reqBean
						, new TypeToken<AppCommonResponse<ResponseData>>() {}.getType());
		PageForLayui page = new PageForLayui();
		if( respBean != null &&  respBean.getSubCode() != null 
				&& respBean.getSubCode().equals(ReturnCodeConstants.SUB_CODE_SUCC)) {			
			page.setCode("0");
			page.setMsg(respBean.getSubMsg());
			page.setCount(respBean.getData().getTotal());
			page.setData(respBean.getData().getDataList());
			return page;
		}else {
			page.setCode(respBean.getSubMsg());
			page.setMsg(respBean.getSubMsg());
		}
		return null;
	}

	@Override
	public Object allinpayQueryFinanceDetails(Map map) throws Exception {
		// TODO Auto-generated method stub
		CommonReqBean reqBean = new CommonReqBean(); 
		reqBean.setBizContent(map);
		reqBean.setReqSsn(SequenceUtil.getAppReqSsn());
		
		
		AppCommonResponse<ResponseData> respBean = restRequestService.postToAppForSingleByObj
				("/trade/query/allinpayQueryFinanceDetails"
						, reqBean
						, new TypeToken<AppCommonResponse<ResponseData>>() {}.getType());
		PageForLayui page = new PageForLayui();
		if( respBean != null &&  respBean.getSubCode() != null 
				&& respBean.getSubCode().equals(ReturnCodeConstants.SUB_CODE_SUCC)) {			
			page.setCode("0");
			page.setMsg(respBean.getSubMsg());
			page.setCount(respBean.getData().getTotal());
			page.setData(respBean.getData().getDataList());
			return page;
		}else {
			page.setCode(respBean.getSubMsg());
			page.setMsg(respBean.getSubMsg());
		}
		return null;
	}

}
